class User < ActiveRecord::Base
  attr_accessible :email, :name, :provider, :uid
  has_many :coupon_infos, :foreign_key => 'customer_id', :dependent => :destroy
  has_many :shop_managers, :foreign_key => 'manager_id'
  has_many :coupon_histories, :foreign_key => 'customer_id', :dependent => :destroy
  has_many :shops, :through => :coupon_infos
  has_many :managing_shops, :class_name => 'Shop', :source => :shop, :through => :shop_managers
  
  def self.create_with_omniauth(auth)
    create! do |user|
      user.provider = auth["provider"]
      user.uid = auth["uid"]
      user.name = auth["info"]["name"]
    end
  end
end
